<div id="app" v-cloak>
    <el-card class="box-card">
        <el-form class="search" :inline="true" :model="vm" ref="vm" label-position="right" label-width="90px">
            <el-form-item label="任务名称" prop="taskName">
                <el-input v-model="vm.taskName" @keyup.enter.native="onSearch" clearable size="mini" placeholder="请输入任务名称"></el-input>
            </el-form-item>
            <el-form-item label="开始时间" prop="startTime">
                <el-date-picker
                        size="mini"
                        v-model="vm.startTime"
                        format="yyyy-MM-dd HH:mm:ss"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        type="datetime"
                        placeholder="选择日期时间">
                </el-date-picker>
            </el-form-item>
            <el-form-item label="结束时间" prop="endTime">
                <el-date-picker
                        size="mini"
                        v-model="vm.endTime"
                        format="yyyy-MM-dd HH:mm:ss"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        type="datetime"
                        placeholder="选择日期时间">
                </el-date-picker>
            </el-form-item>
            <el-form-item label="执行耗时" prop="execTime">
                <el-input v-model="vm.execTime" @keyup.enter.native="onSearch" type="number" clearable size="mini" placeholder="请输入执行耗时" min="-2147483648" max="2147483647" step="1"></el-input>
            </el-form-item>
            <el-form-item label="执行状态" prop="execState">
                <el-select v-model="vm.execState" clearable size="mini" filterable placeholder="请输入执行状态">
                    <el-option key="1" label="成功" value="1"></el-option>
                    <el-option key="0" label="失败" value="0"></el-option>
                </el-select>
                </el-select>
            </el-form-item>
            <el-form-item label="开始日期" prop="startDate">
                <el-date-picker v-model="vm.startDate" clearable size="mini" placeholder="请输入开始日期" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
            </el-form-item>
            <el-form-item label="结束日期" prop="endDate">
                <el-date-picker v-model="vm.endDate" clearable size="mini" placeholder="请输入结束日期" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" size="mini" icon="el-icon-search" @click="onSearch">搜索</el-button>
                <el-button type="warning" size="mini" icon="el-icon-refresh-left" @click="onReset('vm')">重置</el-button>
            </el-form-item>
        </el-form>
    </el-card>

    <el-card class="box-card">
        <el-row type="flex" justify="space-between">
            <el-button-group>
                <#if token.hasRes("/ajax/wsys/logtask/delete")>
                <el-button type="danger" size="mini" icon="el-icon-delete" @click="onBitchDelete">删除</el-button>
                </#if>
            </el-button-group>

            <el-button-group>
            <#if token.hasRes("/ajax/wsys/logtask/template")>
                <el-tooltip effect="dark" content="Excel导入模板下载" placement="bottom">
                    <el-button size="mini" icon="el-icon-date" @click="onTemplate"></el-button>
                </el-tooltip>
            </#if>

            <#if token.hasRes("/ajax/wsys/logtask/imports")>
                <el-tooltip effect="dark" content="Excel导入" placement="bottom">
                    <el-button size="mini" icon="el-icon-upload2" @click="onImport"></el-button>
                </el-tooltip>
            </#if>

            <#if token.hasRes("/ajax/wsys/logtask/exports")>
                <el-tooltip effect="dark" content="Excel导出" placement="bottom">
                    <el-button size="mini" icon="el-icon-download" @click="onExport"></el-button>
                </el-tooltip>
            </#if>

                <el-tooltip effect="dark" content="刷新" placement="bottom">
                    <el-button size="mini" icon="el-icon-refresh" @click="onFind"></el-button>
                </el-tooltip>
            </el-button-group>
        </el-row>

        <el-table
                class="data"
                @selection-change="onSelectionChange"
                empty-text="无数据"
                :stripe="true"
                :data="result"
                size="mini">
            <el-table-column
                    align="center"
                    width="45"
                    type="selection">
            </el-table-column>
            <el-table-column
                    align="center"
                    min-width="120"
                    prop="taskId"
                    label="任务ID">
            </el-table-column>
            <el-table-column
                    align="center"
                    min-width="180"
                    prop="taskName"
                    label="任务名称">
            </el-table-column>
            <el-table-column
                    align="center"
                    min-width="100"
                    prop="execState"
                    label="执行状态">
                <template slot-scope="scope">
                    <el-tag size="mini" v-if="scope.row.execState == '1'">成功</el-tag>
                    <el-tag size="mini" v-if="scope.row.execState == '0'" type="danger">失败</el-tag>
                </template>
            </el-table-column>
            <el-table-column
                    align="center"
                    min-width="140"
                    prop="startTime"
                    label="开始时间">
            </el-table-column>
            <el-table-column
                    align="center"
                    min-width="140"
                    prop="endTime"
                    label="结束时间">
            </el-table-column>
            <el-table-column
                    align="center"
                    min-width="80"
                    prop="execTime"
                    label="执行耗时">
                <template slot-scope="scope">
                    <span>{{scope.row.execTime}}ms</span>
                </template>
            </el-table-column>
            <el-table-column
                    align="center"
                    min-width="180"
                    prop="execResult"
                    label="执行结果">
            </el-table-column>
            <el-table-column
                    align="center"
                    min-width="140"
                    prop="createTime"
                    label="创建时间">
            </el-table-column>
            <el-table-column
                    align="center"
                    width="120"
                    fixed="right"
                    label="操作">
                <template slot-scope="scope">
                    <wb-table-ops :arg="scope.row">
                    <#if token.hasRes("/ajax/wsys/logtask/view")>
                        <wb-table-op value="查看" icon="el-icon-view" @click="onView"></wb-table-op>
                    </#if>
                    <#if token.hasRes("/ajax/wsys/logtask/delete")>
                        <wb-table-op value="删除" icon="el-icon-delete" @click="onDelete"></wb-table-op>
                    </#if>
                    </wb-table-ops>
                </template>
            </el-table-column>
        </el-table>

        <el-pagination
                background
                v-if="vm.totalCount > vm.pageSize"
                style="margin-top: 10px"
                @current-change="onPageChange"
                @size-change="onPageSizeChange"
                :current-page="vm.pageNumber"
                :page-size="vm.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="vm.totalCount">
        </el-pagination>
    </el-card>

    <el-dialog
            :fullscreen="false"
            :title="form.formTitle"
            :custom-class="'dialog'"
            :close-on-click-modal="false"
            :close-on-press-escape="false"
            :modal-append-to-body="true"
            :visible.sync="form.formShow">

        <el-page-header slot="title" @back="form.formShow = false" :content="form.formTitle"></el-page-header>

        <el-form class="form" :model="form" :inline="true" :rules="formRules" ref="form" label-position="right" label-width="90px">
            <el-form-item label="任务ID" prop="taskId">
                <el-input v-model="form.taskId" size="mini" readonly></el-input>
            </el-form-item>
            <el-form-item label="任务名称" prop="taskName">
                <el-input v-model="form.taskName" size="mini" readonly></el-input>
            </el-form-item>
            <el-form-item label="开始时间" prop="startTime">
                <el-input v-model="form.startTime" size="mini" readonly></el-input>
            </el-form-item>
            <el-form-item label="结束时间" prop="endTime">
                <el-input v-model="form.endTime" size="mini" readonly></el-input>
            </el-form-item>
            <el-form-item label="执行耗时" prop="execTime">
                <el-input :value="form.execTime + 'ms'" size="mini" readonly></el-input>
            </el-form-item>
            <el-form-item label="执行状态" prop="execState">
                <el-select v-model="form.execState" clearable size="mini" readonly>
                    <el-option key="1" label="成功" value="1"></el-option>
                    <el-option key="0" label="失败" value="0"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="执行结果" prop="execResult">
                <el-input v-model="form.execResult" style="width: 504px;"
                          size="mini"
                          rows="10"
                          type="textarea"
                          maxlength="500"
                          show-word-limit readonly></el-input>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
			<el-button size="mini" @click="form.formShow = false">关 闭</el-button>
		</span>
    </el-dialog>
</div>
<script>
    var app = new Vue({
        mixins: [mixinForMgr],
        el: "#app",
        data: {
            module: 'wsys',
            target: 'logtask',
            vm: {//条件及分页参数
                taskName: null,
                startTime: null,
                endTime: null,
                execTime: null,
                execState: null,
                startDate: null,
                endDate: null,
                pageNumber: 1,
                pageSize: 10,
                totalCount: 0,
                sortKey:'CREATE_TIME',
                sortType:'DESC'
            },
            form: {
                formTitle: "",
                formShow: false,
                id: "",
                taskId: "",
                taskName: "",
                startTime: "",
                endTime: "",
                execTime: "",
                execState: "",
                execResult: "",
                rowVersion: ""
            },
            formRules: {}
        },
        methods: {
            onView: function (item) {
                this.form.formTitle = "任务日志详情查看";
                this.form.formShow = true;
                this.form.id = item.id;
                this.form.taskId = item.taskId;
                this.form.taskName = item.taskName;
                this.form.startTime = item.startTime;
                this.form.endTime = item.endTime;
                this.form.execTime = item.execTime;
                this.form.execState = item.execState;
                this.form.execResult = item.execResult;
                this.form.rowVersion = item.rowVersion;
            },
            onDelete: function (item) {
                this.$confirm('将删除该项, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(function () {
                    new Ajax("wsys", "logtask").delete({id: item.id}, function (response) {
                        if (response.errors.length > 0) {
                            nav.e(response.errors[0].message);
                        } else {
                            nav.s("删除成功.");
                            this.onFind();
                        }
                    }.bind(this))
                }.bind(this)).catch(function (action) {

                });
            }
        },
        mounted: function () {
            this.onFind();
        }
    })
</script>
